package offer;

public class findNumberIn2DArray_04 {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix == null || matrix.length == 0)return false;
        int n = matrix.length;
        int m = matrix[0].length;
        int i = 0;
        int j = m - 1;

        while (i < n && j >= 0){
            if(matrix[i][j] == target){
                return true;
            } else if(matrix[i][j] < target){
                i++;
            } else{
                j--;
            }
        }
        return false;
    }
}
